import { listAll as listAllInfo, listType as listTypeInfo } from '../services/hot';

export default {
  namespace: 'hot',

  state: {
    typeList: [],
    hotList: [],
  },

  effects: {
    *listAll({ payload }, { call, put }) {
      const response = yield call(listAllInfo, payload);
      response.data.forEach((item, index) => {
        item.rank = index + 1;
        if(index === 0){
          item.color = "#f15a22";
        }else if(index === 1){
          item.color = "#ffc20e";
        }else if(index === 2){
          item.color = "#cd9a5b";
        }else{
          item.color = "#fff";
        }
      });
      yield put({
        type: 'loadAllList',
        payload: response.data,
      });
    },
    *listType(_, { call, put }) {
      const response = yield call(listTypeInfo);
      yield put({
        type: 'loadTypeList',
        payload: response.data,
      });
    },
  },

  reducers: {
    loadAllList(state, action) {
      return {
        ...state,
        hotList: action.payload,
      };
    },
    loadTypeList(state, action) {
      return {
        ...state,
        typeList: action.payload,
      };
    },
  },
};
